package com.example.yckjbigdataflink.utils;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;

import java.io.IOException;

public class KerberosUtil {
    public static void login(String krb5ConfPath, String keytabPath, String principal) throws IOException {
        System.setProperty("java.security.krb5.conf", krb5ConfPath);

        Configuration conf = new Configuration();
        conf.set("hadoop.security.authentication", "kerberos");
        UserGroupInformation.setConfiguration(conf);

        UserGroupInformation.loginUserFromKeytab(principal, keytabPath);
    }
}

